﻿Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.Data.OleDb

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
<System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class tagger
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function getTagsFromPrefix(ByVal prefixText As String) As String()
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("mobilestandardsdb").ConnectionString)
        oleDbConn.Open()
        Dim getTagsSql As String = "SELECT Tag FROM Tags WHERE Tag LIKE @prefixText"
        Dim tagsDbCmd = New OleDbCommand(getTagsSql, oleDbConn)
        prefixText = Replace(prefixText, "%", "")
        prefixText = prefixText & "%"
        tagsDbCmd.Parameters.AddWithValue("@prefixText", prefixText)
        Dim tagsDbReader = tagsDbCmd.ExecuteReader()
        Dim foundTagsList As New List(Of String)
        If tagsDbReader.HasRows() Then
            While tagsDbReader.Read()
                foundTagsList.Add(tagsDbReader("Tag"))
            End While
        End If
        Return foundTagsList.ToArray()
    End Function

End Class